﻿
-- ================================================
-- Remarks: 
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Dasideen_Sys_SessionLog_Insert')
	BEGIN
		DROP  Procedure  Dasideen_Sys_SessionLog_Insert
	END

GO

CREATE PROCEDURE [Dasideen_Sys_SessionLog_Insert]
-- =============================================
-- Author:		<Sagar s.k>
-- Create date: <12/05/2015>
-- Description:	<Dasideen_Sys_SessionLog_Insert>
-- ============================================= 
-- Add the parameters for the stored procedure here
	(
				
				@UserSessionID varchar(500),
				@UserIPAddress varchar(50) = NULL,
				@UserSessionStartTime datetime = NULL,
				@UserSessionEndTime datetime = NULL,
				@UserBrowserName nvarchar(50) = NULL,
				@UserKey int = NULL,

				@Sys_CreatedByID varchar(50)= NULL,
				@Sys_ModifiedByID varchar(50) = NULL,
				@Sys_DeleteType int = 0,
				@Sys_OrganizationID int = NULL,
				@Sys_InitialPrimaryKeys varchar(max)= NULL,
				@Sys_WorkstationName varchar(50)= NULL,

			    @Sys_DateOfCreation datetime OUTPUT,
				@SessionLogPrimaryID int OUTPUT
	)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	IF @Sys_WorkstationName = 'Default'	
	BEGIN
		SET @Sys_WorkstationName = (SELECT @@SERVERNAME);
	END
	DECLARE @CurrentDataTime datetime;
	SET @CurrentDataTime = GETDATE();
	
    INSERT INTO [Sys_SessionLog]
           (	
				[UserSessionID],
				[UserIPAddress],
				[UserSessionStartTime],

				[UserBrowserName],
				[UserKey],
				
				[Sys_DateOfCreation],
				[Sys_DateOfModification],
				[Sys_CreatedByID],
				[Sys_ModifiedByID],
				[Sys_DeleteType],
				[Sys_IsDeleted],
				[Sys_OrganizationID],
				[Sys_InitialPrimaryKeys],
				[Sys_WorkstationName]
			)
     VALUES
           (
				@UserSessionID,
				@UserIPAddress,
				@CurrentDataTime,
			
				@UserBrowserName,
				@UserKey,

				@CurrentDataTime,
				@CurrentDataTime,
				@Sys_CreatedByID,
				@Sys_ModifiedByID,
				@Sys_DeleteType,
				0,
				@Sys_OrganizationID,
				@Sys_InitialPrimaryKeys,
				@Sys_WorkstationName
			);
			SET @SessionLogPrimaryID = SCOPE_IDENTITY();
			SET @Sys_DateOfCreation = @CurrentDataTime;
END
GO
